cat('Creating Table A30 \n\n')

dat = read.csv('TableA30_data.csv')
dat.uo = dat[dat$uo.non.uo == 'uo',]
dat.sec = dat[dat$uo.non.uo != 'uo',]

##formulas specific to trust
use.formula = as.formula(paste('outgroup_close_numeric ~ ',master.formula,sep = ''))
use.formula.reduced = as.formula(paste('outgroup_close_numeric ~ ',master.formula.reduced,sep = ''))
use.formula.interactions = as.formula(paste('outgroup_close_numeric ~ ',master.formula.interactions,sep = ''))

##UO
##regressions
reg.uo.pub = lm(use.formula, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub, dat.uo$index.city)
reg.uo.pub$se = clustered.se

reg.uo.pub.reduced = lm(use.formula.reduced, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.reduced, dat.uo$index.city)
reg.uo.pub.reduced$se = clustered.se

reg.uo.pub.interactions = lm(use.formula.interactions, data = dat.uo)
clustered.se = cl(dat.uo, reg.uo.pub.interactions, dat.uo$index.city)
reg.uo.pub.interactions$se = clustered.se

##Secular
##regressions
reg.sec.pub = lm(use.formula, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub, dat.sec$index.city)
reg.sec.pub$se = clustered.se

reg.sec.pub.reduced = lm(use.formula.reduced, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.reduced, dat.sec$index.city)
reg.sec.pub.reduced$se = clustered.se

reg.sec.pub.interactions = lm(use.formula.interactions, data = dat.sec)
clustered.se = cl(dat.sec, reg.sec.pub.interactions, dat.sec$index.city)
reg.sec.pub.interactions$se = clustered.se

outtable = apsrtable(reg.uo.pub.reduced,
                     reg.uo.pub,
                     reg.uo.pub.interactions,
                     reg.sec.pub.reduced,
                     reg.sec.pub, 
                     reg.sec.pub.interactions,
                     Sweave = T,
                     stars = 'default',
                     coef.names = coef.names,
                     model.names = c('UO','UO','UO','Non UO','Non UO','Non UO'),
                     notes = ''
                      )
writeLines(
  outtable, 'TableA30.tex')